﻿Public Class frm_SpilitQty
#Region "Khai báo biến"
    Public gvInt_Quantity As Integer
    Dim mvBol_Close As Boolean = False
    Dim mvUrc_Caculator As New urc_Calculator()
#End Region
#Region "Hàm khởi tạo"
    Private Sub SubM_InitializeForm()
        AddHandler mvUrc_Caculator.txtInput.TextChanged, AddressOf txtInput_TextChanged
        mod_Format.Sub_ShowControl(mvUrc_Caculator, 26)
        Me.mvBol_Close = False
        mvUrc_Caculator.txtInput.Text = Me.txtCurrentQty.Text
        Me.txtReturnQty.Text = mvUrc_Caculator.txtInput.Text
    End Sub
#End Region
#Region "Form events"
    Private Sub frm_DiscountServiceVat_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Not mvBol_Close Then
            e.Cancel = True
        End If
    End Sub
    Private Sub frm_DiscountServiceVat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SubM_InitializeForm()
    End Sub
#End Region
#Region "Textchange"
    Private Sub txtInput_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.txtReturnQty.Text = mvUrc_Caculator.txtInput.Text
        Dim mvDbl_CurrentQty As Double = 0
        Dim mvDbl_ReturnQty As Double = 0
        Try
            If IsNumeric(Me.txtCurrentQty.Text) Then
                mvDbl_CurrentQty = Convert.ToDouble(Me.txtCurrentQty.Text)
            End If
            If IsNumeric(Me.txtReturnQty.Text) Then
                mvDbl_ReturnQty = Convert.ToDouble(Me.txtReturnQty.Text)
            End If
            Me.txtRemainQty.Text = Math.Round(mvDbl_CurrentQty - mvDbl_ReturnQty, 0).ToString
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Nút confirm"
    Private Sub cmdConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConfirm.Click
        Try
            If Not IsNumeric(mvUrc_Caculator.txtInput.Text) Then
                FunG_Alert("Thông báo lỗi!", "Yêu cầu nhập số!", frm_Alert.WTYPE.ERROR)
            Else
                If Convert.ToDouble(Me.txtReturnQty.Text) > Convert.ToDouble(Me.txtCurrentQty.Text) Then
                    FunG_Alert("Thông báo lỗi!", "Số lượng cần chuyển phải nhỏ hơn số lượng hiện tại!", frm_Alert.WTYPE.ERROR)
                Else
                    'Trả về số lượng cần chuyển
                    gvInt_Quantity = Me.txtReturnQty.Text
                    mvBol_Close = True
                    Me.Close()
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Nút exit"
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        gvInt_Quantity = 0
        mvBol_Close = True
        Me.Close()
    End Sub
#End Region
End Class